<?php

class Participante_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function guardaParticipante($transaccion) {
        if ($this->input->post("participanteId") || $this->input->post("participanteId") != "") {
            $sql = "update participantes set 
                    participanteTipDoc = '{$this->input->post("participanteTipDoc")}',
                   participanteDocumento = '{$this->input->post("participanteDocumento")}',
                   participanteNombres = '{$this->input->post("participanteNombres")}',
                   participanteInstLabora = '{$this->input->post("participanteInstLabora")}',";
            if ($this->input->post("txtAyuda"))
                $sql .= "participanteApoyoInst = '{$this->input->post("txtAyuda")}',";
            $sql .= "participanteCargo = '{$this->input->post("txtCargo")}'
                    where `participanteId` = '{$this->input->post("participanteId")}'";
            $this->db->query($sql);
            $personaId = $this->input->post("participanteId");
        }else {
            $sql = "select * from participantes where `participanteTipDoc` = '{$this->input->post("participanteTipDoc")}' and `participanteDocumento` = '{$this->input->post("participanteDocumento")}'";
            $result = $this->db->query($sql);
            if ($result->num_rows() == 0) {
                $sql = "insert into participantes(`participanteTipDoc`,`participanteDocumento`,`participanteNombres`,`participanteInstLabora`,`participanteCargo`,participanteApoyoInst) values(";
                $sql .= "'{$this->input->post("participanteTipDoc")}','{$this->input->post("participanteDocumento")}','{$this->input->post("participanteNombres")}','{$this->input->post("participanteInstLabora")}','{$this->input->post("txtCargo")}','{$this->input->post("txtAyuda")}')";
                $result = $this->db->query($sql);
                $personaId = $this->db->insert_id();
            } else {
                $personaId = $result->result();
                $personaId = $personaId[0]->participanteId;
            }
        }
        $sql = "select * from temporal where transaccion = '$transaccion' and indiceInt = '$personaId'";
        $result = $this->db->query($sql)->num_rows();
        if ($result == 0) {
            $sql = "insert into temporal(transaccion,`indiceInt`) values(";
            $sql .= "'$transaccion','$personaId')";
            $temp = $this->db->query($sql);
        }
        return true;
    }

}

//fin class
?>
